import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 消息类型枚举 */
export enum MessageTypeEnum {
  /** 文本消息 */
  Text = 1,
  /** 图片消息 */
  Image = 2,
  /** 语音消息 */
  Voice = 3,
  /** 视频消息 */
  Video = 4,
  /** 文件消息 */
  File = 5,
  /** 图文消息 */
  News = 6,
  /** 数据消息 */
  Data = 7,
}

/** 消息类型实体 */
export class MessageTypeEntity {
  /** 消息类型 */
  MessageType: MessageTypeEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(messageType: MessageTypeEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.MessageType = messageType;
    this.Color = color;
    switch (messageType) {
      case MessageTypeEnum.Text:
        // this.Display = '文本消息';
        this.Display = t('enum.messageType.text');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case MessageTypeEnum.Image:
        // this.Display = '图片消息';
        this.Display = t('enum.messageType.image');
        this.Color = this.Color ? this.Color : PresetColorEnum.Cyan;
        break;
      case MessageTypeEnum.Voice:
        // this.Display = '语音消息';
        this.Display = t('enum.messageType.voice');
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case MessageTypeEnum.Video:
        // this.Display = '视频消息';
        this.Display = t('enum.messageType.video');
        this.Color = this.Color ? this.Color : PresetColorEnum.Gold;
        break;
      case MessageTypeEnum.File:
        // this.Display = '文件消息';
        this.Display = t('enum.messageType.file');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case MessageTypeEnum.News:
        // this.Display = '图文消息';
        this.Display = t('enum.messageType.news');
        this.Color = this.Color ? this.Color : PresetColorEnum.Lime;
        break;
      case MessageTypeEnum.Data:
        // this.Display = '数据消息';
        this.Display = t('enum.messageType.data');
        this.Color = this.Color ? this.Color : PresetColorEnum.Magenta;
        break;
    }
  }
}

//#region 获取消息类型枚举架构
/**
 * 获取消息类型枚举架构
 */
export function getMessageTypeEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: MessageTypeEntity[] = [
    new MessageTypeEntity(MessageTypeEnum.Text),
    new MessageTypeEntity(MessageTypeEnum.Image),
    new MessageTypeEntity(MessageTypeEnum.Voice),
    new MessageTypeEntity(MessageTypeEnum.Video),
    new MessageTypeEntity(MessageTypeEnum.File),
    new MessageTypeEntity(MessageTypeEnum.News),
    new MessageTypeEntity(MessageTypeEnum.Data),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.MessageType as number,
      label: item.Display,
      value: item.MessageType as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
